home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / putpict.c < prev    next >
C/C++ Source or Header  |  1986-04-20  |  4KB  |  91 lines

  1.  
  2. /** putpict.c ***************************************************/
  3. /* PutPict().  Given a BitMap and a color map in RAM on the      */
  4. /* Amiga, outputs as an ILBM.  See /iff/ilbm.h & /iff/ilbmw.c.   */
  5. /*                   23-Jan-86                    */
  6. /*                                                              */
  7. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  8. /* This software is in the public domain.                       */
  9. /*                                                              */
  10. /* This version for the Commodore-Amiga computer.               */
  11. /*                                                              */
  12. /****************************************************************/
  13. #include "iff/intuall.h"
  14. #include "iff/gio.h"
  15. #include "iff/ilbm.h"
  16. #include "iff/putpict.h"
  17.  
  18. #define MaxDepth 5
  19. static IFFP ifferror = 0;
  20.  
  21. #define CkErr(expression)  {if (ifferror == IFF_OKAY) ifferror = (expression);}
  22.     
  23. /*****************************************************************************/
  24. /* IffErr                                                                    */
  25. /*                                                                           */
  26. /* Returns the iff error code and resets it to zero                          */
  27. /*                                                                           */
  28. /*****************************************************************************/
  29. IFFP IffErr()
  30.    {
  31.    IFFP i;
  32.    i = ifferror;
  33.    ifferror = 0;
  34.    return(i);
  35.    }
  36.  
  37. /*****************************************************************************/
  38. /* PutPict()                                                                 */
  39. /*                                                                           */
  40. /* Put a picture into an IFF file                                            */
  41. /* Pass in mask == NULL for no mask.                                         */
  42. /*                                                                           */
  43. /* Buffer should be big enough for one packed scan line                      */
  44. /* Buffer used as temporary storage to speed-up writing.                     */
  45. /* A large buffer, say 8KB, is useful for minimizing Write and Seek calls.   */
  46. /* (See /iff/gio.h & /iff/gio.c).                                            */
  47. /*****************************************************************************/
  48.     
  49. BOOL PutPict(file, bm, pageW, pageH, colorMap, buffer, bufsize)
  50.       LONG file; struct BitMap *bm; 
  51.      WORD pageW,pageH;
  52.      WORD *colorMap;
  53.       BYTE *buffer;  LONG bufsize;
  54.     {
  55.     BitMapHeader bmHdr;
  56.     GroupContext fileContext, formContext;
  57.          
  58.     ifferror = InitBMHdr(&bmHdr,
  59.      bm, 
  60.      mskNone, 
  61.      cmpByteRun1, 
  62.      0,
  63.      pageW, 
  64.      pageH );
  65.      
  66. /* use buffered write for speedup, if it is big-enough for both
  67.  * PutBODY's buffer and a gio buffer.*/
  68. #define BODY_BUFSIZE 512
  69.     if (ifferror == IFF_OKAY  &&  bufsize > 2*BODY_BUFSIZE) {
  70.      if (GWriteDeclare(file, buffer+BODY_BUFSIZE, bufsize-BODY_BUFSIZE) < 0)
  71.          ifferror = DOS_ERROR;
  72.      bufsize = BODY_BUFSIZE;
  73.      }
  74.     
  75.     CkErr(OpenWIFF(file, &fileContext, szNotYetKnown) );
  76.     CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext) );
  77.  
  78.     CkErr(PutCk(&formContext, ID_BMHD, sizeof(BitMapHeader), (BYTE *)&bmHdr));
  79.  
  80.     if (colorMap!=NULL)
  81.      CkErr( PutCMAP(&formContext, colorMap, (UBYTE)bm->Depth) );
  82.     CkErr( PutBODY(&formContext, bm, NULL, &bmHdr, buffer, bufsize) );
  83.  
  84.     CkErr( EndWGroup(&formContext) );
  85.     CkErr( CloseWGroup(&fileContext) );
  86.     if (GWriteUndeclare(file) < 0  &&  ifferror == IFF_OKAY)
  87.      ifferror = DOS_ERROR;
  88.     return( (BOOL)(ifferror != IFF_OKAY) );
  89.     }    
  90.  
  91.